package com.aboo.rocketmq.service;

import com.aboo.frame.util.rocketmq.MqMsg;
import com.aboo.frame.util.rocketmq.SendMqUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.producer.SendStatus;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class RocketMqService {

    public boolean sendMq(String msg) {
        if (StringUtils.isBlank(msg)) {
            return false;
        }

        String topic = "yata_topic";
        String tag = "tag001";
        MqMsg mqMsg = new MqMsg();
        mqMsg.setTopic(topic);
        mqMsg.setTag(tag);
        mqMsg.setBody(msg);

        SendStatus status = SendMqUtil.sendMsg(mqMsg);
        log.info("发送MQ数据：{}，结果：{}", msg, status);
        if (status == SendStatus.SEND_OK) {
            return true;
        }

        return false;
    }

}
